<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改套餐')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-meal-edit" th:object="${meal}">
            <input name="id" th:field="*{id}" type="hidden">
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">套餐名称：</label>
                <div class="col-sm-8">
                    <input name="mealName" th:field="*{mealName}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">套餐同时在线数：</label>
                <div class="col-sm-8">
                    <input name="useCount" th:field="*{useCount}" class="form-control" type="number" required="digits">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">套餐周期（小时）：</label>
                <div class="col-sm-8">
                    <input name="useHour" th:field="*{useHour}" class="form-control" type="number" required="digits">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">套餐金额（元）：</label>
                <div class="col-sm-8">
                    <input name="price" th:field="*{price}" class="form-control" type="text" required="min:0">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">状态：</label>
                <div class="col-sm-8">
                    <div class="radio-box" th:each="dict : ${@dict.getType('radius_meal_status')}">
                        <input type="radio" th:id="${dict.dictCode}" name="enable" th:value="${dict.dictValue}" th:field="*{enable}">
                        <label th:for="${dict.dictCode}" th:text="${dict.dictLabel}"></label>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">排序：</label>
                <div class="col-sm-8">
                    <input name="sortNumber" th:field="*{sortNumber}" class="form-control" type="number">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <textarea name="remark" class="form-control" th:field="*{remark}"></textarea>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var prefix = ctx + "radius/meal";
        $("#form-meal-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                var form = $('#form-meal-edit').serializeArray();
                form.forEach(item =>{
                    if(item.name == "price"){
                        item.value = Math.round($("#price").val() * 100) + "";;
                        return;
                    }
                })
                $.operate.save(prefix + "/edit", form);
            }
        }
        $(function () {
            $("#price").val($("#price").val() / 100);
        })
    </script>
</body>
</html>